package scuba.DiveBuddy;

import android.app.ActionBar;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import scuba.DiveBuddy.Adapters.LogViewerAdapter;
import scuba.DiveBuddy.Core.Core;

/**
 * @author Alex Anderson
 * @version 1.0
 * @since {04/03/14}
 */
public class LogEntryViewerActivity extends FragmentActivity
        implements ActionBar.TabListener,
        ViewPager.OnPageChangeListener {


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_newlogentry);
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        //Setup Tabs
        ViewPager pager = (ViewPager)findViewById(R.id.tabs);
        LogViewerAdapter adapter = new LogViewerAdapter(getSupportFragmentManager());
        pager.setAdapter(adapter);

        for (String s : Core.LOGPAGE_TABS)
            getActionBar().addTab(getActionBar().newTab()
                    .setText(s)
                    .setTabListener(this));

        pager.setOnPageChangeListener(this);
    }


    //<editor-fold desc="------> Options Menu">
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.logviewer_actions, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId())
        {
            case R.id.action_cancel:
                finish();
                break;

            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }
    //</editor-fold>

    //<editor-fold desc="------> Tab Selection">
    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {
        ((ViewPager)findViewById(R.id.tabs)).setCurrentItem(tab.getPosition());

    }
    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }
    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }
    //</editor-fold>

    //<editor-fold desc="------> OnPageChangeListener">
    @Override
    public void onPageScrolled(int i, float v, int i2) {

    }

    @Override
    public void onPageSelected(int i) {
        getActionBar().setSelectedNavigationItem(i);
    }

    @Override
    public void onPageScrollStateChanged(int i) {

    }
    //</editor-fold>

}